package com.smartboard.network.ui;

import android.widget.EditText;
import android.widget.Spinner;

import com.smartboard.network.R;
import com.smartboard.network.game.GameInfoGobang;
import com.smartboard.network.game.IRoom;

/**
 * Created by cheas on 2018/8/23.
 */

public class CreateGameDialogGobang extends CreateGameDialog {

    private Spinner mBoardSizeSpinner;
    private EditText mTotalTimeText;
    private EditText mGameNumText;

    public CreateGameDialogGobang(GameActivity activity, IRoom room) {
        super(activity, room);
    }

    @Override
    protected void initViews() {
        setContentView(R.layout.dialog_create_game_gobang);
        mBoardSizeSpinner = (Spinner)findViewById(R.id.boardSize);
        mTotalTimeText = (EditText)findViewById(R.id.total_time);
        mGameNumText = (EditText)findViewById(R.id.game_num);
    }

    @Override
    protected boolean checkFieldValid() {
        boolean ret = true;
        if(mTotalTimeText.getText().length() == 0) {
            mTotalTimeText.setError(getContext().getString(R.string.error_field_required));
            ret = false;
        } else if(mGameNumText.getText().length() == 0) {
            mGameNumText.setError(getContext().getString(R.string.error_field_required));
            ret = false;
        }
        return ret;
    }

    @Override
    protected Object getGameInfo() {
        GameInfoGobang gameInfo = new GameInfoGobang();
        gameInfo.mBoardSize = Integer.parseInt((String)mBoardSizeSpinner.getSelectedItem());
        gameInfo.mTotalTime = Integer.parseInt(mTotalTimeText.getText().toString());
        return gameInfo;
    }
    @Override
    protected int getGameNum() {
        return Integer.parseInt(mGameNumText.getText().toString());
    }

}
